<template>
  <div class="form-layout">
    <!--左侧导航-->
    <div class="nav-left">
      <customAnchor
        :itemList="cpCustomAnchor"
      />
    </div>

    <!--表单区域-->
    <div class="form-right" ref="formRight">

      <!--数据导入配置-->
      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly || cpDesignDisabled" v-show="cpViewType == 'import'">
        <template #content>
          <div id="box-base-import" class="box-title">基础配置</div>
          <customFormItem label="配置标识" name="viewKey" :parent="_self" :form="form" />
          <customFormItem label="配置名称" name="viewName" :parent="_self" :form="form" />
          <customFormItem label="基础表" name="baseTable" :parent="_self" :form="form" />
          <customFormItem
            label="配置类型"
            name="viewType"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.selectStatic.name"
            :config="{ options: constCommon.nobusConst.viewTypeList }"
          />
          <customFormItem label="配置描述" name="description" :parent="_self" :form="form" />

          <div id="box-import" class="box-title">导入字段配置</div>
          <detailBtn ref="tableImportBtn" :data="columns" type="tableImportBtn"  :disabled="propReadonly || cpDesignDisabled"></detailBtn>
        </template>
      </customForm>

      <customForm :data="form" :rules="propRules" ref="editForm" :disabled="propReadonly || cpDesignDisabled" v-show="['base', 'select'].includes(cpViewType)">
        <template #content>
          <div id="box-base" class="box-title">基础配置</div>
          <customFormItem
            label="配置类型"
            name="viewType"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.selectStatic.name"
            :config="{ options: constCommon.nobusConst.viewTypeList }"
          />
          <customFormItem label="配置标识" name="viewKey" :parent="_self" :form="form" />
          <customFormItem label="配置名称" name="viewName" :parent="_self" :form="form" />

          <customFormItem label="配置描述" name="description" :parent="_self" :form="form" />
          <customFormItem label="不使用默认配置" name="flagColumnsDefaultConfig" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>

          <div id="box-base-action" class="box-title">后台访问配置</div>
          <customFormItem label="列表查询" name="listEntry" :parent="_self" :form="form" fullWidth/>
          <customFormItem label="单个查询" name="queryEntry" :parent="_self" :form="form" fullWidth />
          <customFormItem label="保存" name="saveEntry" :parent="_self" :form="form" fullWidth />
          <customFormItem label="删除" name="deleteEntry" :parent="_self" :form="form" fullWidth />
          <customFormItem label="流程提交" name="flowEntry" :parent="_self" :form="form" fullWidth />
          <customFormItem label="分页查询" name="showPagination" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="主键字段" name="primaryKey" :parent="_self" :form="form" />


          <div id="box-list-btn" class="box-title">列表顶部按钮</div>
          <customFormItem label="添加" name="showViewButtonAdd" :parent="_self" :form="buttonConfig"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="删除" name="showViewButtonDelete" :parent="_self" :form="buttonConfig"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="刷新" name="showViewButtonRefresh" :parent="_self" :form="buttonConfig"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="显示最大化按钮" name="showMaxZoom" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="显示导入按钮" name="showImport" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem
            label="导入配置"
            name="importViewKey"
            :parent="_self"
            :form="form"
            help="使用哪个导入配置"
            :readonly="true"
            :showSelectIcon="true"
            @focus="$refs.tableDrawerImportSelect.show()"
          />
          <customFormItem label="显示导出按钮" name="showExport" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="自定义导出地址" name="exportAddr" :parent="_self" :form="form" fullWidth/>
          <detailBtn  ref="tableBaseBtn"  :data="viewButtons"  type="tableBaseBtn"  :disabled="propReadonly || cpDesignDisabled"/>

          <div id="box-list-btn-right" class="box-title">列表右侧按钮</div>
          <customFormItem label="详情" name="showRowButtonDetail" :parent="_self" :form="buttonConfig"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="编辑" name="showRowButtonEdit" :parent="_self" :form="buttonConfig"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="删除" name="showRowButtonDelete" :parent="_self" :form="buttonConfig"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="操作区域宽度" name="tableOpWidth" :parent="_self" :form="form" :type="constCommon.formItemType.inputNumber.name" help="根据按钮实际宽度配置即可，不指定则自动计算"/>
          <detailBtn  ref="tableColumnBtn"  :data="form.rowButtons"  type="tableColumnBtn"  :disabled="propReadonly || cpDesignDisabled"/>


          <div id="box-list-column" class="box-title">列表显示配置</div>
          <customFormItem label="显示复选框" name="showCheckbox" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="显示单选框" name="showRadiobox" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="使用行编辑" name="editable" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="高亮显示条件" name="rowAlertEval" :parent="_self" :form="form" help="行高亮显示条件,如: row.name = '刘德华'" full-width/>
          <customFormItem label="高亮显示提醒" name="rowAlertMsg" :parent="_self" :form="form" help="用户提醒行信息，将在初始化提醒一次" full-width/>
          <customFormItem label="显示顶部汇总" name="flagSumTop" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="顶部汇总查询" name="sumTopUrl" :parent="_self" :form="form" full-width
                          help="如:/finance/bill/sumTopHigh，适用于一个控制层有多个不同的数据视图，此时通过覆盖父类方法没法有效区别，可以分别指定不同的汇总接口"
          />
          <customFormItem
            label="数据过滤"
            name="dataFilterType"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.selectStatic.name"
            :config="{ options: constCommon.nobusConst.dataFilterTypeList }"
          />

          <customFormItem
            label="过滤字段"
            name="dataFilterField"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.selectStatic.name"
            :config="{ options: columns, label: 'title', value: 'name' }"
            help="指定后按照指定的字段进行过滤，不指定则按照内置逻辑过滤"
          />

          <customFormItem label="禁用日期初始查询" help="禁用后日期字段，初始化将不添加查询条件" name="disabledDateFirst" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="行启用编辑条件" name="rowEnableCondition"  :parent="_self" :form="form" help="不可编辑时：隐藏行内删除、编辑按钮,隐藏表单非编辑按钮，如: data.status == 1,data指的是行数据对象" fullWidth/>

          <!--操作按钮-->
          <customSpace fullWidth v-if="!cpDesignDisabled">
            <template #content>
              <customButton  title="刷新列-根据表结构" theme="primary" size="medium" @click="btnOp('columnByTable', '根据表结构刷新当前网格列')" help="根据表结构刷新当前网格列"/>
              <customButton  title="刷新列-根据数据结构" theme="primary" size="medium" @click="btnOp('columnByData', '根据查询接口返回数据格式刷新当前网格列')"  help="根据查询接口返回数据格式刷新当前网格列"/>
            </template>
          </customSpace>
          <detailColumns  ref="detailColumnsListColumn"  :data="columns"  :disabled="propReadonly || cpDesignDisabled"></detailColumns>

          <div id="box-dialog" class="box-title">表单窗口配置</div>
          <customFormItem label="窗口标题" name="viewFormTitle" :parent="_self" :form="form"/>
          <customFormItem
            label="窗口尺寸"
            name="formDrawerWidth"
            :parent="_self"
            :form="form"
            :type="constCommon.formItemType.selectStatic.name"
            :config="{ options: constCommon.nobusConst.formDrawerWidthList }"
          />
          <customFormItem label="窗口宽度" name="viewFormWidthPx" :parent="_self" :form="form" :type="constCommon.formItemType.inputNumber.name" help="像素，如果指定了则以此属性为主"/>
          <customFormItem label="窗口高度" name="viewFormHeightPx" :parent="_self" :form="form" :type="constCommon.formItemType.inputNumber.name" help="像素，如果指定了则以此属性为主"/>
          <customFormItem label="自动保存" name="viewFormAutoSave" :parent="_self" :form="form" :type="constCommon.formItemType.switch.name" help="true: 当用户修改了表单后，将自动保存数据"/>

          <div id="box-form-btn" class="box-title">表单按钮配置</div>
          <customFormItem label="添加按钮" name="showViewFormButtonAdd" :parent="_self" :form="buttonConfig"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="保存按钮" name="showViewFormButtonSave" :parent="_self" :form="buttonConfig"  :type="constCommon.formItemType.switch.name"/>
          <customFormItem label="删除按钮" name="showViewFormButtonDelete" :parent="_self" :form="buttonConfig"  :type="constCommon.formItemType.switch.name"/>
          <detailBtn  ref="detailBtnFormBtn"  :data="form.viewFormButtons"  type="formBtn"  :disabled="propReadonly || cpDesignDisabled"/>

          <div id="box-form" class="box-title">表单字段配置</div>
          <detailColumnsInput   ref="detailColumnsInput" :data="baseColumns"  :disabled="propReadonly || cpDesignDisabled"></detailColumnsInput>

          <div id="box-print" class="box-title">打印配置</div>
          <customFormItem label="不显示序号" name="noPrintSeq" :parent="_self" :form="form"  :type="constCommon.formItemType.switch.name"/>
        </template>
      </customForm>

      <customForm :data="form" :rules="propRulesBuild" ref="editFormBuild" :disabled="propReadonly || cpDesignDisabled" v-show="['base', 'select'].includes(cpViewType)">
        <template #content>
          <div id="box-build" class="box-title">文件生成</div>
          <customFormItem label="配置标识" name="viewKey" :parent="_self" :form="form" />
          <customFormItem label="配置名称" name="viewName" :parent="_self" :form="form" />
          <customFormItem label="基础表" name="baseTable" :parent="_self" :form="form" />
          <customFormItem label="包名" fullWidth name="basePackageName" :parent="_self" :form="form" help="后台包的基础路径，如 com.scs.application.modules.base"/>

          <customFormItem label="后端生成路径" fullWidth name="buildPathServer" :parent="_self" :form="form" @change="buildPathChange"
                          help="绝对路径，可以使用临时目录，或者直接写项目路径。不指定则不生成" appendBtn>
            <template #appendBtn>
              <customButton
                title="生成后端文件"
                theme="success"
                @click="btnOp('buildPathServer', '生成后端文件')" help="根据配置生成后端文件：后端controller、service、mapper"

              >
              </customButton>
            </template>
          </customFormItem>
          <customFormItem label="前端生成路径" fullWidth name="buildPathWeb" :parent="_self" :form="form" @change="buildPathChange" fullWidth
                          help="绝对路径，可以使用临时目录，或者直接写项目路径。不指定则不生成" appendBtn>
            <template #appendBtn>
              <customButton
                title="生成前端文件"
                theme="success"
                @click="btnOp('buildPathWeb', '生成前端文件')" help="根据配置生成前端文件：列表、编辑页面"
              >
              </customButton>
            </template>
          </customFormItem>
        </template>
      </customForm>
    </div>

    <!--流程选择-->
    <tableDrawer ref="tableDrawerImportSelect" @confirm="tableDrawerImportSelectConfirm" viewKey="system_dv_define" :queryWrapper="cpImportSelectQueryWrapper"/>
  </div>
</template>

<script>
import customAnchor from '@/components/custom/form/customAnchor.vue'
import detailBtn from './detail-btn.vue'
import detailColumns from './detail-columns.vue'
import detailColumnsInput from './detail-columns-input.vue'

export default {
  components: {
    customAnchor, detailColumns, detailColumnsInput, detailBtn
  },
  data() {
    return {
      form: {},
      viewData: {},
      columns: [],
      buttonConfig: {},
      baseColumns: [],
      viewButtons: [],
      propRulesBuild: {
        viewKey: [{ required: true, message: '请输入', trigger: 'blur' }],
        viewName: [{ required: true, message: '请输入', trigger: 'blur' }],
        baseTable: [{ required: true, message: '请输入', trigger: 'blur' }],
        basePackageName: [{ required: true, message: '请输入', trigger: 'blur' }],
      }
    }
  },
  created() {
    let that = this
    this.$emit('event-register', {
      validate: (callback) => {
        return this.$refs.editForm.validate(callback)
      },
      beforeSave: () => {
        if (this.cpViewType == 'import') {
          if (this.$refs.tableImportBtn) {
            this.form.columns = this.$refs.tableImportBtn.valueThis
          }
        } else {
          if (this.$refs.tableBaseBtn) {
            this.form.viewButtons = this.$refs.tableBaseBtn.valueThis
          }
          if (this.$refs.tableColumnBtn) {
            this.form.rowButtons = this.$refs.tableColumnBtn.valueThis
          }
          if (this.$refs.detailBtnFormBtn) {
            this.form.viewFormButtons = this.$refs.detailBtnFormBtn.valueThis
          }
          if (this.$refs.detailColumnsListColumn) {
            this.form.columns = this.columns
          }
          if (this.$refs.detailColumnsInput) {
            this.form.baseColumns = this.baseColumns
          }
        }
        this.form.configReserveButtons = this.buttonConfig
        this.form.rules = this.getValidateRules()
        Object.keys(this.form).forEach(key => {
          if (this.utilNum.isNum(key)) {
            delete this.form[key]
          }
        })
        this.$emit('data-callback', this.form)
        return true
      },
      afterMove: (formData, initData) => {
        this.form = global.utils.jsonClone(formData)
        this.viewData = this.propCurrentRow
        this.form.editStatus = this.propStatus

        this.columns = this.form.columns ? JSON.parse(JSON.stringify(this.form.columns)) : []
        let configReserveButtons = this.form.configReserveButtons ? JSON.parse(JSON.stringify(this.form.configReserveButtons)) : {}
        if (configReserveButtons instanceof Array ) {
        } else {
          this.buttonConfig = configReserveButtons
        }
        this.baseColumns = this.form.baseColumns ? JSON.parse(JSON.stringify(this.form.baseColumns)) : []
        this.viewButtons = this.form.viewButtons ? JSON.parse(JSON.stringify(this.form.viewButtons)) : []
        if (this.cpDesignDisabled) {
          this.utilMessage.warning('当前系统不允许编辑表单配置')
          this.propParent.viewFormButtons.forEach(btn => {
            this.propParent.setButtonInvisible('viewForm', btn.key, true)
          })
        }
        if (this.form)  {
          this.form.buildPathServer = localStorage.getItem('buildPathServer')
          this.form.buildPathWeb = localStorage.getItem('buildPathWeb')
        }
      },
      afterSave: () => {},
      beforeDelete: () => {
        return true
      },
      afterDelete: () => {},
      beforeFlow: (flowButtonKey) => {
        return true
      },
      afterFlow: (flowButtonKey) => {},
      beforeClose: () => {
        return true
      },
      afterClick(button, data, viewForm) {
        let {key: buttonKey} = button
        if (buttonKey == 'vfb-copy') { //复制
          that.utilMessage.confirmInput('请输入新的配置标识', (viewKeyNew) => {
            let viewFormDataNew = JSON.parse(JSON.stringify(that.form))
            viewFormDataNew.viewKey = viewKeyNew
            viewFormDataNew.editStatus = 'addnew'
            delete  viewFormDataNew.id
            that.utilVue.loadShow(true)
            that.$ajax.post('/program/data-view/save', viewFormDataNew).then(resp => {
              that.utilVue.loadHide()
              if (resp.code == 0) {
                that.utilMessage.success('复制成功')
                // that.utilMessage.confirm('复制成功，是否进行编辑', () => {
                //   that.propParent.viewRowOne(viewFormDataNew.viewKey, false, 'viewKey')
                // })
              }
            })
          })
        }
      }
    })
  },
  props: [
    'propPrimaryKey',
    'propDictionaries',
    'propCurrentRow',
    'propViewFormData',
    'propReadonly',
    'propStatus',
    'propRules',
    'propInitData',
    'propParent'
  ],
  computed: {
    // 是否是导入类型的配置
    cpViewType() {
      return this.strings.defaultString(this.form.viewType,'base')
    },
    // 是否是导入类型的配置
    cpCustomAnchor() {
      if (this.cpViewType == 'import') {
        return [
          { name: 'box-base', title: '基础配置' },
          { name: 'box-import', title: '导入字段配置' },
        ]
      }

      return [
        { name: 'box-base', title: '基础配置' },
        { name: 'box-base-action', title: '后台访问配置' },
        { name: 'box-list-btn', title: '列表顶部按钮' },
        { name: 'box-list-btn-right', title: '列表右侧按钮' },
        { name: 'box-list-column', title: '列表显示配置' },
        { name: 'box-dialog', title: '表单窗口配置' },
        { name: 'box-form-btn', title: '表单按钮配置' },
        { name: 'box-form', title: '表单字段配置' },
        { name: 'box-print', title: '打印配置' },
        { name: 'box-build', title: '文件生成' },
      ]
    },
    // 基础列
    cpImportSelectQueryWrapper() {
      let wrapper = this.$newWrapper()
      wrapper.eq('view_type', 'import')
      return wrapper
    },
    // 基础列
    cpDesignDisabled() {
      return !this.parameters.allowProjectDesign(this)
    }
  },
  methods: {
    // 用户操作
    btnOp(type, msg) {
      this.utilMessage.confirm(`是否${msg}`, () => {
        this.btnOpExec(type, msg)
      })
    },
    // 根据表结构刷新网格列
    async columnByTable(refreshColumns) {
      let inputType = 'text'
      refreshColumns.forEach((col, index) => { //先转驼峰
        this.$set(col, 'name', global.utils.toHump(col.name))
      })

      //删除新的列中没有的
      let baseColumnIndexDelete = []
      let baseColumnNameDelete = []
      let baseColumnDelete = []
      this.baseColumns.forEach((col, index) => { //删除新的列中没有的
        if (refreshColumns.filter(column => column.name == col.name).length == 0) {
          baseColumnIndexDelete.push(index)
          baseColumnNameDelete.push(col.name)
          baseColumnDelete.push(col)
        }
      })

      let baseColumnAdd = []
      let baseColumnNameAdd = []
      refreshColumns.forEach((col, index) => { //增加新的
        if (this.baseColumns && this.baseColumns.filter(column => column.name == col.name).length > 0) {
          return
        }
        if (col.columnKey === 'PRI') {
          inputType = 'none'
          this.$set(this.form, 'primaryKey', col.name)
        } else if (col.dataType === 'date' || col.dataType === 'datetime') {
          inputType = 'date'
        } else if (col.dataType === 'bit') {
          inputType = 'checkbox'
        } else {
          inputType = 'text'
        }
        this.$set(col, 'inputType', inputType)
        const title = col.title || ''
        this.$set(col, 'title', title.split('|')[0])
        // 加入默认的校验规则
        const rules = []
        this.$set(col, 'rule', rules)
        baseColumnAdd.push(col)
        baseColumnNameAdd.push(col.name)
      })

      // 新增字段
      baseColumnAdd.forEach(column => {
        this.baseColumns.push(column)
        this.columns.push(column)
      })
      baseColumnDelete.forEach(index => {
        this.baseColumns.splice(index, 1)
        this.columns.splice(index, 1)
      })
      this.utilMessage.alertSuccess(`<div>新增字段</div><div>${baseColumnNameAdd.join(',')}</div><div>删除字段</div><div>${baseColumnNameDelete.join(',')}</div>`)

      if (this.columns.length < 1) {
        this.baseColumns.forEach((col, index) => {
          this.columns.push({
            name: col.name,
            title: col.title,
            width: 200,
            sort: index * 10,
            queryType: 'none'
          })
        })
      }
    },
    // 根据查询接口返回数据格式刷新当前网格列
    async columnByData(data) {
      if (!data) return
      // 清除没有的列
      let columnDelete = []
      let columnNameDelete = []
      let dataKeyList = Object.keys(data)

      //基础列
      this.columns.forEach(column => {
        if (!dataKeyList.includes(column.name) ) {
          columnDelete.push(column)
          columnNameDelete.push(column.name)
        }
      })

      // 网格列
      let baseColumnDelete = []
      let baseColumnNameDelete = []
      this.baseColumns.forEach(column => {
        if (!dataKeyList.includes(column.name)) {
          baseColumnDelete.push(column)
          baseColumnNameDelete.push(column.name)
        }
      })


      let columnAdd = []
      let columnNameAdd = []
      let baseColumnAdd = []
      let baseColumnNameAdd = []
      dataKeyList.forEach(item => {
        const findIndex = this.columns.findIndex(col => col.name === item)
        if (findIndex < 0) {
          columnAdd.push({ name: item, title: item, width: '200', queryType: 'none' })
          columnNameAdd.push(item)
        }

        const findIndex2 = this.baseColumns.findIndex(col => col.name === item)
        if (findIndex2 < 0) {
          baseColumnAdd.push({ name: item, title: item, width: '200', queryType: 'none' })
          baseColumnNameAdd.push(item)
        }
      })
      baseColumnAdd.forEach(column => {
        this.baseColumns.push(column)
      })

      //基础字段 也新增
      if (columnAdd.length > 0) {
        columnAdd.forEach(column => {
          this.columns.push(column)
        })
      }

      baseColumnDelete.forEach(column => {
        let columnIndex = this.baseColumns.findIndex(column2 => column2.name == column.name )
        if (columnIndex != -1) this.baseColumns.splice(columnIndex, 1)
      })

      //基础字段也删除
      if (columnDelete.length > 0) {
        columnDelete.forEach(column => {
          let columnIndex = this.columns.findIndex(column2 => column2.name == column.name )
          if (columnIndex != -1) this.columns.splice(columnIndex, 1)
        })
      }

      this.utilMessage.alertSuccess(`<div>新增字段</div><div>${baseColumnNameAdd.join(',')}</div><div>删除字段</div><div>${baseColumnNameDelete.join(',')}</div>`)
    },
    // 用户操作
    btnOpExec(type, msg) {
      switch (type) {
        case 'columnByTable': { //根据表结构刷新当前网格列
          if (!this.form.baseTable || this.form.baseTable.length < 1) {
            this.utilMessage.warning('请先设置基础表！')
            return false
          }
          const params = {
            tableName: this.form.baseTable
          }
          this.$ajax.get('/program/table-columns', { params }).then(res => {
            if (res.success) {
              this.columnByTable(res.data)
              this.utilMessage.success('刷新成功')
            }
          })
          break
        }
        case 'columnByData': {//根据查询接口返回数据格式刷新当前网格列
          if (!this.form.listEntry || this.form.listEntry.length < 1) {
            this.utilMessage.alertFail('请先设置列表入口！')
            return false
          }
          //参数过多，服务器异常，此处改为post请求
          let reqType = 'get'
          if (this.form.listEntry.indexOf('pageWithStock') != -1) {
            reqType = 'post'
          }
          let params = {currentPage:1, rowsPerPage:1, mode: 'schema'}
          this.$ajax[reqType](this.form.listEntry, { params }).then(res => {
            if (res.code == '0') {
              if (res.data.length > 0) {
                this.columnByData(res.data[0])
              } else {
                this.utilMessage.warning('列表入口查询没有返回数据，至少设置一条模拟数据先！')
              }
            }
          })
          break
        }
        case 'buildPathServer': {//生成后端文件
          this.$refs.editFormBuild.validate().then(result => {
            if (result === true) {
              if (this.strings.isBlank(this.form.buildPathServer)) {
                this.utilMessage.warning('请输入后端生成路径')
                return
              }
              const params = {
                tableName: this.form.baseTable,
                basePackageName: this.form.basePackageName,
                buildPathServer: this.form.buildPathServer,
                buildPathWeb: null,
                viewKey: this.form.viewKey,
                viewName: this.form.viewName,
              }
              this.utilVue.loadShow(true)
              this.$ajax.post('/program/create-all', params).then(res => {
                this.utilVue.loadHide()
                if (res.code == '0') {
                  this.utilMessage.success('文件已生成')
                }
              })
            }
          })
          break
        }
        case 'buildPathWeb': {//生成前端文件
          this.$refs.editFormBuild.validate().then(result => {
            if (result === true) {
              if (this.strings.isBlank(this.form.buildPathWeb)) {
                this.utilMessage.warning('请输入前端生成路径')
                return
              }
              const params = {
                tableName: this.form.baseTable,
                basePackageName: this.form.basePackageName,
                buildPathServer: null,
                buildPathWeb: this.form.buildPathWeb,
                viewKey: this.form.viewKey,
                viewName: this.form.viewName,
              }
              this.utilVue.loadShow(true)
              this.$ajax.post('/program/create-all', params).then(res => {
                this.utilVue.loadHide()
                if (res.code == '0') {
                  this.utilMessage.success('文件已生成')
                }
              })
            }
          })
          break
        }
      }
    },
    // 选择完导入模板
    tableDrawerImportSelectConfirm(row) {
      this.$set(this.form,'importViewKey', row.viewKey)
    },
    getValidateRules() {
      const rules = {}
      if (!this.baseColumns || this.baseColumns.length == 0) {
        return rules
      }
      this.baseColumns.forEach(field => {
        if (field.rule) {
          if (typeof field.rule == 'string') {
            field.rule = JSON.parse(field.rule)
          }
          rules[field.name] = this.parseRule(field.rule)
        }
      })
      return rules
    },
    parseRule(rule) {
      const rules = []
      rule.forEach(item => {
        rules.push(item.content)
      })
      return rules
    },
    buildPathChange() {
      localStorage.setItem('buildPathServer', this.form.buildPathServer)
      localStorage.setItem('buildPathWeb', this.form.buildPathWeb)
    }
  },
}
</script>
